#ifndef MYBUTTON_H
#define MYBUTTON_H
#include "qpushbutton.h"
#include <string.h>
#include <iostream>
#include "QPoint"
#include "MyAnimation.h"
#include "ui_mainwindow.h"
using namespace std;
class MyButton : public QPushButton
{
    Q_OBJECT
   public:
       QPropertyAnimation* animator = NULL;
       MyButton(QWidget *,int,int,int value);
       MyButton(QWidget *,MyButton*,int,int value);
       QWidget *parent_widget;//获得父级widget
       double r_x,r_y;//相对坐标比例系数
       QPoint getP();//获得此点坐标
       QPoint getCenter();//获得按钮中间坐标
       void res_position();//动态变化坐标
       QPropertyAnimation* MoveAni_Straight(QPoint);//直线移动
       QPropertyAnimation* MoveAni_Circle(QPoint,MyAnimation::PathType);//曲线移动
       QPoint positionForParent(MyButton*);//根据父亲节点生成坐标
       void convert_vector(QWidget*);//转换为相对坐标
       MyButton *father,*lchild,*rchild;//父亲节点（与parent重复避免混淆）,左右孩子
       int direct = -1;//-1没有父亲，0是左孩子，1是右孩子
       int Height;
       int Data;
       int GetHeight(MyButton*);
       int GetBalancedFactor(MyButton*);
       void UpdateHeight(MyButton*);
       MyButton* InsertNode(QWidget *,MyButton*,MyButton*,int,int);
       MyButton* L(MyButton*);
       MyButton* R(MyButton*);
       QPropertyAnimation* Preorder_Ani(MyButton* node,int,MyAnimation::PathType);
       MyButton* DeleteButton(MyButton*,int);
       MyButton* UpdateFatherHeight(MyButton*);
       void Traversal(MyButton *);
       MyButton* Rotate(MyButton*);
       MyButton* FatherJudge(MyButton*);
   protected:
       virtual void enterEvent(QEvent *);
       virtual void leaveEvent(QEvent *);
       virtual void mousePressEvent(QMouseEvent*);
    private:
       QString resPathstatic = ":/new/prefix1/button.png";//资源路径
       QString resPathstatic2 = ":/new/prefix1/delete1.png";
       QPixmap *pixmap;
       double value;//值
       int radius = 50;//点的半径
       enum finddirect{
           LD = -1,
           RD = 1,
           ALL = 0
       };
};

#endif // MYBUTTON_H
